#include<stdio.h>

int removeElement(int* nums, int numsSize, int val) {
    int* pos;
    int* end;
    pos = end = nums;
    int new_val = 0;
    for (int i = 0; i < val; i++)
    {
        if (*pos != numsSize)
        {
            if (pos != end)
            {
                *(end) = *(pos);
            }
            end++;
            new_val++;
        }
        pos++;
    }
    return new_val;
}

int removeDuplicates(int* nums, int numsSize) {
    int* pos;
    int* end;
    pos = end = nums;
    int new_numsSize = 0;
    for (int i = 0; i < numsSize; i++)
    {
        if (end == pos)
        {
            pos++;
            new_numsSize++;
            continue;

        }
        if (*pos == *end)
        {
            pos++;
        }
        else
        {
            end++;
            *end = *pos;
            pos++;
            new_numsSize++;
        }
    }
    return new_numsSize;
}

void merge(int* nums1, int nums1Size, int m, int* nums2, int nums2Size, int n) {

    int i, j, pos;
    i = m - 1, j = n - 1, pos = nums1Size - 1;
    while (pos >= 0)
    {
        while (i >= 0 && j >= 0)
        {
            if (nums2[j] > nums1[i])
            {
                nums1[pos] = nums2[j];
                pos--;
                j--;
            }
            else
            {
                nums1[pos] = nums1[i];
                pos--;
                i--;
            }
        }
        if (i >= 0)
        {
            break;
        }
        if (j >= 0)
        {
            nums1[j] = nums2[j];
            pos--;
            j--;
        }
    }
}

int main()
{
    int a[] = { 1,1,2,2,3,4,5,6,7 };
    int n = sizeof(a) / sizeof(a[0]);
    //n = removeElement(a, n, 3);
    n = removeDuplicates(a, n);
    for(int i = 0; i < n; i++)
    {
       printf("%d ", a[i]);
    }

}